import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ling
 * Date: 2022-10-19
 * Time: 20:18
 */
@WebServlet("/message")
public class Demo1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String aa=req.getParameter("aa");
        String bb=req.getParameter("bb");
        resp.getWriter().write("aa: "+aa+" bb "+bb );
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        String aa=req.getParameter("aa");
//        String bb=req.getParameter("bb");
//        resp.getWriter().write("aa:"+aa+" bb:"+bb);
        ObjectMapper mapper =new ObjectMapper();
        Message message = mapper.readValue(req.getInputStream(),Message.class);
        resp.getWriter().write("aa:"+message.aa+" bb:"+message.bb);
    }
}
class Message {
    public String aa;
    public String bb;
}